package com.springboot.cms.broadside.controller;

import com.springboot.cms.broadside.domain.CmsBroadside;
import com.springboot.cms.broadside.service.ICmsBroadsideService;
import com.springboot.common.annotation.Log;
import com.springboot.common.core.controller.BaseController;
import com.springboot.common.core.domain.AjaxResult;
import com.springboot.common.core.page.TableDataInfo;
import com.springboot.common.enums.BusinessType;
import com.springboot.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 侧边栏管理Controller
 *
 * @author lhxz
 * @date 2024-07-08
 */
@RestController
@RequestMapping("/cms/broadside")
public class CmsBroadsideController extends BaseController
{
    @Autowired
    private ICmsBroadsideService cmsBroadsideService;

    /**
     * 查询侧边栏管理列表
     */
//    @PreAuthorize("@ss.hasPermi('cms:broadside:list')")
    @GetMapping("/list")
    public TableDataInfo list(CmsBroadside cmsBroadside)
    {
        startPage();
        List<CmsBroadside> list = cmsBroadsideService.selectCmsBroadsideList(cmsBroadside);
        return getDataTable(list);
    }

    /**
     * 导出侧边栏管理列表
     */
    @PreAuthorize("@ss.hasPermi('cms:broadside:export')")
    @Log(title = "侧边栏管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmsBroadside cmsBroadside)
    {
        List<CmsBroadside> list = cmsBroadsideService.selectCmsBroadsideList(cmsBroadside);
        ExcelUtil<CmsBroadside> util = new ExcelUtil<CmsBroadside>(CmsBroadside.class);
        util.exportExcel(response, list, "侧边栏管理数据");
    }

    /**
     * 获取侧边栏管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('cms:broadside:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(cmsBroadsideService.selectCmsBroadsideById(id));
    }

    /**
     * 新增侧边栏管理
     */
    @PreAuthorize("@ss.hasPermi('cms:broadside:add')")
    @Log(title = "侧边栏管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmsBroadside cmsBroadside)
    {
        return toAjax(cmsBroadsideService.insertCmsBroadside(cmsBroadside));
    }

    /**
     * 修改侧边栏管理
     */
    @PreAuthorize("@ss.hasPermi('cms:broadside:edit')")
    @Log(title = "侧边栏管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmsBroadside cmsBroadside)
    {
        return toAjax(cmsBroadsideService.updateCmsBroadside(cmsBroadside));
    }

    /**
     * 删除侧边栏管理
     */
    @PreAuthorize("@ss.hasPermi('cms:broadside:remove')")
    @Log(title = "侧边栏管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cmsBroadsideService.deleteCmsBroadsideByIds(ids));
    }
}
